'use strict'

const Service = require('egg').Service

class AdminUserService extends Service {
  // 注册
  async register(params) {
    const { ctx, app } = this
    const user = await app.model.AdminUser.findOne({ where: { username: params.username } })
    if (user) ctx.throw(400, '用户名已存在')
    return app.model.AdminUser.create(params)
  }
  // 根据用户id查找用户
  async findById(id) {
    return await this.app.model.AdminUser.findOne({
      where: {
        id
      },
      attributes: {
        exclude: ['password']
      }
    })
  }
}

module.exports = AdminUserService
